import uuid
from typing import Any

import pytest

from recruit.application.commands.create_user import CreateUser
from recruit.application.protocols import UoW
from recruit.domain.exceptions.user import UserExistsError
from recruit.domain.models.user import UserCreate
from recruit.domain.services.user import UserService
from tests.gateway import UserGateway


@pytest.mark.parametrize(
    'data', [
        {
            'user_id': 1,
            'username': '@username'
        }
    ]
)
async def test_create_user(data: dict[str, Any], mock_uow: UoW) -> None:
    user_id = uuid.uuid4()
    created_user = CreateUser(
        uow=mock_uow,
        user_db_gateway=UserGateway(user_id=user_id),
        user_service=UserService()
    )
    user = await created_user(UserCreate(**data))
    assert user.id == user_id
    assert user.username == data['username']
    assert user.user_id == data['user_id']
    created_user = CreateUser(
        uow=mock_uow,
        user_db_gateway=UserGateway(user_id=user_id, is_user=True),
        user_service=UserService()
    )
    with pytest.raises(UserExistsError):
        await created_user(UserCreate(**data))
